package org.stvd.controller.admin;

import java.text.ParseException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.stvd.controller.BaseController;
import org.stvd.core.dto.QueryResult;
import org.stvd.entities.admin.Loginfo;
import org.stvd.service.admin.LoginfoService;

import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@Controller
@RequestMapping("/admin/loginfo")
public class LoginfoController extends BaseController {
   
    @Autowired
    LoginfoService loginfoService;

    // 查询页面begin
    @RequestMapping(value = "management")
    public String onPageLoad(HttpServletRequest request, @ModelAttribute("loginfo") Loginfo loginfo) {
        try {
            map.put("queryResult", onQuery(request, map, pageNo, pageSize, loginfo.getUser_name(),
                    loginfo.getLog_type(), loginfo.getLog_type(), loginfo.getBeginDate(), loginfo.getEndDate()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "/admin/loginfo/LoginfoManagement.html";
    }

    public QueryResult<Loginfo> onQuery(HttpServletRequest request, ModelMap map, int page, int rows, String username,
        String log_type, String log_type2, Date beginDate, Date endDate) throws ParseException {
        return loginfoService.getLoginfoResult((page - 1) * rows, rows, 
            username, log_type, log_type2, beginDate, endDate);
    }

}